From: mjw@wray-m-3.hpl.hp.com Date: Thu, 1 Jul 2004 07:41:45 +0000 (+0000) Subject: bitkeeper revision 1.1041.1.4 (40e3c039GLJ7sRSdIoNOD2_oAJinLQ) X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~18074^2~16 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=798ce800b1fede6de291fa96f76ae6c2b42b8205;p=xen.git bitkeeper revision 1.1041.1.4 (40e3c039GLJ7sRSdIoNOD2_oAJinLQ) Small fixes. --- diff --git a/tools/python/xen/xend/server/SrvDaemon.py b/tools/python/xen/xend/server/SrvDaemon.py index 31ace1b84e..9050166bf4 100644 --- a/tools/python/xen/xend/server/SrvDaemon.py +++ b/tools/python/xen/xend/server/SrvDaemon.py @@ -14,6 +14,7 @@ import socket import pwd import re import StringIO +import traceback from twisted.internet import pollreactor pollreactor.install() @@ -396,6 +397,12 @@ class EventProtocol(protocol.Protocol): eserver.inject(sxp.name(event), event) return ['ok'] + def op_traceon(self, name, v): + self.daemon.tracing(1) + + def op_traceoff(self, name, v): + self.daemon.tracing(0) + class EventFactory(protocol.Factory): """Asynchronous handler for the event server socket. @@ -428,6 +435,7 @@ class Daemon: """ def __init__(self): self.shutdown = 0 + self.traceon = 0 def daemon_pids(self): pids = [] @@ -486,7 +494,7 @@ class Daemon: while code > 0: code = os.waitpid(-1, os.WNOHANG) - def start(self,trace=0): + def start(self, trace=0): if self.cleanup(kill=False): return 1 @@ -510,7 +518,21 @@ class Daemon: # Child logfile = self.open_logfile() self.redirect_output(logfile) - if trace: + + self.tracing(trace) + + self.run() + return 0 + + def tracing(self, traceon): + """Turn tracing on or off. + + traceon tracing flag + """ + if traceon == self.traceon: + return + self.traceon = traceon + if traceon: self.tracefile = open('/var/log/xend.trace', 'w+', 1) self.traceindent = 0 sys.settrace(self.trace) @@ -518,26 +540,35 @@ class Daemon: threading.settrace(self.trace) # Only in Python >= 2.3 except: pass - self.run() - return 0 - def print_trace(self,str): + def print_trace(self, str): for i in range(self.traceindent): - self.tracefile.write(" ") + ch = " " + if (i % 5): + ch = ' ' + else: + ch = '|' + self.tracefile.write(ch) self.tracefile.write(str) def trace(self, frame, event, arg): + if not self.traceon: + print >>self.tracefile + print >>self.tracefile, '-' * 20, 'TRACE OFF', '-' * 20 + self.tracefile.close() + self.tracefile = None + return None if event == 'call': code = frame.f_code filename = code.co_filename - m = re.search('.*xenmgr/(.*)', code.co_filename) + m = re.search('.*xend/(.*)', filename) if not m: return None modulename = m.group(1) if re.search('sxp.py', modulename): return None self.traceindent += 1 - self.print_trace("++++ %s:%s\n" + self.print_trace("> %s:%s\n" % (modulename, code.co_name)) elif event == 'line': filename = frame.f_code.co_filename @@ -547,15 +578,18 @@ class Daemon: elif event == 'return': code = frame.f_code filename = code.co_filename - m = re.search('.*xenmgr/(.*)', code.co_filename) + m = re.search('.*xend/(.*)', filename) if not m: return None modulename = m.group(1) - self.print_trace("---- %s:%s\n" + self.print_trace("< %s:%s\n" % (modulename, code.co_name)) self.traceindent -= 1 elif event == 'exception': - pass + self.print_trace("! Exception:\n") + (ex, val, tb) = arg + traceback.print_exception(ex, val, tb, 10, self.tracefile) + #del tb return self.trace def open_logfile(self): diff --git a/tools/python/xen/xend/server/channel.py b/tools/python/xen/xend/server/channel.py index d68f84fa37..3382890034 100755 --- a/tools/python/xen/xend/server/channel.py +++ b/tools/python/xen/xend/server/channel.py @@ -216,11 +216,13 @@ class Channel(BaseChannel): def getLocalPort(self): """Get the local port. """ + if self.closed: return -1 return self.port.local_port def getRemotePort(self): """Get the remote port. """ + if self.closed: return -1 return self.port.remote_port def close(self): @@ -233,6 +235,7 @@ class Channel(BaseChannel): self.factory.channelClosed(self) self.devs = [] self.devs_by_type = {} + del self.port def registerDevice(self, types, dev): """Register a device controller. @@ -273,8 +276,8 @@ class Channel(BaseChannel): def __repr__(self): return ('' % (self.dom, - self.port.local_port, - self.port.remote_port)) + self.getLocalPort(), + self.getRemotePort())) def handleNotification(self, type): work = 0 @@ -285,6 +288,7 @@ class Channel(BaseChannel): self.notify() def notify(self): + if self.closed: return self.port.notify() def handleRequests(self):